from rest_framework.throttling import SimpleRateThrottle

# 继承SimpleRateThrottle，重写get_cache_key方法，返回什么就以什么作为频率限制
class SMSThrottle(SimpleRateThrottle):
    # 在配置文件中配置频率时间
    scope = "sms"
    def get_cache_key(self, request, view):
        telephone=request.query_params.get("telephone")
        # cache_format = 'throttle_%(scope)s_%(ident)s'
        return self.cache_format%{'scope':self.scope,'ident':telephone}